<template>
  <el-container>
    <el-header>
      <div class="logo">
        <img src="../../assets/img/hp.jpg" />
      </div>
      <div class="title"><span>新冠物资管理系统</span></div>
      <div class="operation">
        <el-dropdown trigger="click" @command="handleCommand">
          <span class="el-dropdown-link">
            <img src="../../assets/img/hp.jpg" />
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item icon="el-icon-user" command="user"
              >个人中心</el-dropdown-item
            >
            <el-dropdown-item icon="el-icon-paperclip" command="link"
              >学术论坛</el-dropdown-item
            >
            <el-dropdown-item icon="el-icon-delete" command="logout"
              >退出登录</el-dropdown-item
            >
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </el-header>
    <el-container>
      <el-aside width="isCollapse?'60px':'200px'">
        <!-- 折叠的div -->
        <div class="collapse" @click="doCollapse">| | |</div>
        <!-- 侧边栏 -->
        <el-menu
          :collapse="isCollapse"
          :router="true"
          :collapse-transition="false"
          unique-opened
          @open="handleOpen"
          @close="handleClose"
          background-color="#272c33"
          text-color="#fff"
          active-text-color="#ffd04b"
        >
          <Menu :menuData="menuData"></Menu>
        </el-menu>
      </el-aside>
      <el-container>
        <el-main>
          <router-view> </router-view>
        </el-main>
        <el-footer>Footer</el-footer>
      </el-container>
    </el-container>
  </el-container>
</template>

<script>
import { tree } from "../../api/menu";
import Menu from "../../components/Menu/index.vue";
export default {
  data() {
    return {
      isCollapse: false,
      menuData: [],
    };
  },
  components: {
    Menu,
  },
  methods: {
    //获取侧边头像下拉框事件
    handleCommand(command) {
      if (command === "logout") {
        this.$router.push("login");
      }
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    doCollapse() {
      this.isCollapse = !this.isCollapse;
    },
    async getMenuTreeList() {
      let result = await tree();
      this.menuData = result.data.tree;
      console.log(result);
    },
  },
  created() {
    this.getMenuTreeList();
  },
};
</script>

<style lang="less" scoped>
.el-container {
  height: 100%;
}

.el-header {
  display: flex;
  justify-content: space-between;
  background-color: #272c33;
  padding: 0 20px;

  img {
    width: 60px;
    height: 60px;
    border-radius: 50%;
  }
}

.login {
  margin-left: 20px;
}

.title {
  color: white;
  font-size: 26px;
  line-height: 60px;
}

.operation {
  margin-right: 20px;
}

.el-submenu {
  width: 200px;
}

.el-aside {
  background-color: #272c33;

  .collapse {
    background-color: #272c33;
    text-align: center;
    font-size: 26px;
    height: 30px;
    line-height: 30px;
    letter-spacing: 0.2em;
  }
}

.el-main {
}
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}
.el-icon-arrow-down {
  font-size: 12px;
}
.el-menu {
  border: 0;
}
</style>